<?php
if(!defined('BASEPATH'))
    exit ('No direct script access allowed');
class Schedule extends CI_Controller {
    private $page;
    public function __construct() {
        parent::__construct();
        $user_data = $this->session->all_userdata();
        if (isset($user_data["logged_in"]) && $user_data["logged_in"] == TRUE) {
            $this->page["header"] = $this->load->view("part/header_login", '', true);
        } else {
            $this->page["header"] = $this->load->view("part/header_no_login", '', true);
        }
    }

    /**
     * Action   :index
     * Purpose  :View schedule lists and their actions.
     * Date     :
     * Author   :
     */
    public function index(){
        $page = $this->page;
         $page['schedule'] = $this->load->view("page/schedule/index", $data, true);
        $this->load->view("layout", $page);
    }
    /**
     * Action   :build
     * Purpose  :Build schedule for learning path which has #path_id
     * Date     :
     * Author   :
     */
    public function build($id) {
        $page = $this->page;
        $this->load->model('path_model', 'path');
        $this->load->model('schedule_model', 'schedule');
        $getId = $this->path->browseId($id);
        if ($getId == null)
            echo "Không tìm thấy lộ trình có id=" . $id;
        else {
            $submitBuild = $this->input->post("submitBuild");
            if (!$submitBuild) {
                $data["path"] = $getId[0];
                $newestVersion = $this->path->getPathNewestVersion($id);
                $path_information = $this->path->getInformation($newestVersion[0]["id"]);
                $data["information"] = $path_information[0];
                $data["information"]["comment_number"] = $this->path->commentNumber($id);
                $data["information"]["rating_number"] = $this->path->ratingNumber($id);
                $data["section"] = $this->path->getSection($newestVersion[0]["id"]);
                foreach ($data["section"] as $key => $secion) {
                    $data["action"][$secion["id"]] = $this->path->getAction($secion["id"]);
                }
                $data["contributor"] = $this->path->getContributor($id);
                $data["tag"] = $this->path->getTag($id);
                $page["content"] = $this->load->view('page/schedule/build', $data, true);
                $this->load->view('layout', $page);
            } else {
                $_date = $this->input->post("date");
                echo "<pre>";
                print_r($_date);
                echo "</pre>";
                $member_id=1;//Lấy từ session
                $this->schedule->buildSchedule($id, $member_id, $_date);
                $page["content"] = "Đã xây dựng kế hoạch thành công!";
                $this->load->view('layout', $page);
            }
        }
    }
}

/* End of file schedule.php */
/* Location: ./application/controllers/schedule.php */